package webserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class WebServer {

	// 启动服务
	public void serverStart(int port) {
		try {
			// 监听80端口
			ServerSocket serverSocket = new ServerSocket(80);
			
			// test push

			// 一旦有用户来访问
			while (true) {
				Socket socket = serverSocket.accept();

				// 调用线程处理
				new Processor(socket).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		int port = 80;
		if (args != null && args.length == 1) {
			port = Integer.parseInt(args[0]);
		}

		new WebServer().serverStart(port);
	}

}
